package tool

import java.io.File

import cats.data.Validated
import dao.SampleDao
import implicits.Implicits._
import models.Tables._
import org.joda.time.DateTime
import play.api.libs.json.Json
import play.api.mvc.RequestHeader
import shared.Pojo.{SeqData, StrReadsData}
import shared.VarTool
import tool.Pojo._
import tool.Tool._
import utils.Utils

import scala.concurrent.ExecutionContext.Implicits.global
import scala.xml.{Node, XML}


/**
 * Created by yz on 12/3/2020
 */
trait ProjectFileTool {

  def getReportDir(dir: File) = {
    new File(dir, "report")
  }

  def getUserCompareMissionDir(implicit request: RequestHeader) = {
    val userIdDir = getUserIdDir
    new File(userIdDir, "compare_mission")
  }

  def getUserCompareMissionDir(userId:Int) = {
    val userIdDir = getUserIdDir(userId)
    new File(userIdDir, "compare_mission")
  }

  def getUserCompareMissionIdDir(missionId: Int)(implicit request: RequestHeader) = {
    val missionDir = Tool.getUserCompareMissionDir
    new File(missionDir, s"${missionId}")
  }

  def getUserCompareMissionWorkspaceDir(missionId: Int)(implicit request: RequestHeader) = {
    val missionIdDir = Tool.getUserCompareMissionIdDir(missionId)
    new File(missionIdDir, s"workspace")
  }

  def getReadsFile(dir: File) = {
    new File(dir, "reads.txt")
  }

  def getVennDataFile(dir: File) = {
    new File(dir, "venn_data.txt")
  }

  def getDiffReadsDataFile(dir: File) = {
    new File(dir, "diff_reads_data.txt")
  }

  def getDiffSnpDataFile(dir: File) = {
    new File(dir, "diff_snp_data.txt")
  }

  def getUserMissionDir(userId: Int) = {
    val userIdDir = getUserIdDir(userId)
    new File(userIdDir, "mission")
  }

  def getUserStepMissionDir(userId: Int) = {
    val userIdDir = getUserIdDir(userId)
    new File(userIdDir, "step_mission")
  }

  def getUserMissionDir(mission:MissionRow):File={
    (mission.kind match {
      case  VarTool.batchMissionStr=>Tool.getUserMissionDir(mission.userId)
      case  VarTool.compareMissionStr=>Tool.getUserCompareMissionDir(mission.userId)
    })
  }

  def getUserStepMissionDir(mission:StepMissionRow):File={
     Tool.getUserStepMissionDir(mission.userId)
  }

  def getMissionIdDir(mission: MissionRow)(implicit request: RequestHeader) = {
    val userMissionFile = getUserMissionDir(mission)
    new File(userMissionFile,s"${mission.id}")
  }

  def getStepMissionIdDir(mission: StepMissionRow)(implicit request: RequestHeader) = {
    val userMissionFile = getUserStepMissionDir(mission)
    new File(userMissionFile,s"${mission.id}")
  }


}
